package cn.edu.scau.cmi.xianjiehua.singleton;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class Main extends Application {
	
	Stage stage = new Stage();
	
    public void showWindow(){
    	start(stage);
    }

	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void start(Stage primaryStage) {
		TextField textField = new TextField();
		Button button = new Button("创建主席");
		TextArea textArea = new TextArea();

		Chairman.getSingleton("毛泽东");

		button.setOnAction(new EventHandler<ActionEvent>() {
			@Override
			public void handle(ActionEvent e) {
				Chairman chairman2 = Chairman.getSingleton(textField.getText());
				String text = textArea.getText();
				textArea.setText(text + chairman2.getName() + "主席已创建!\n");
			}
		});

		GridPane grid = new GridPane();
		grid.setPadding(new Insets(10, 10, 10, 10));
		grid.setVgap(5);
		grid.setHgap(5);
		GridPane.setConstraints(textField, 0, 0);
		grid.getChildren().add(textField);
		grid.add(button, 1, 0);
		textArea.setPrefColumnCount(10); // 设置列
		textArea.setPrefRowCount(10); // 设置行
		textArea.setLayoutY(300);
		GridPane.setConstraints(textArea, 0, 3);
		GridPane.setColumnSpan(textArea, 2);
		grid.getChildren().add(textArea);
		Scene scene = new Scene(grid, 350, 350);

		primaryStage.setScene(scene);
		primaryStage.show();
		// 控件添加到布局里面，布局添加到scene中，设置scene大小，scene添加到stage，显示stage
	}

}